/**
 * Copyright 2009 Wisdom
 */
package com.wisdom.model.entities;

import java.util.Date;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

/**
 * Entity represent of user content in system
 * 
 * @author alekseiko
 * @since 1.0
 */
@Entity
@Table(name = "WE_CONTENTS")
public class Content {

    private long id;
    private String path;
    private String name;
    private String summary;
    private Date loadDate;
    private User owner;

    /**
     * Default constructor.
     */
    public Content() {
    }

    /**
     * Constructor initialize all fields
     * 
     * @param id
     *            - unique content id
     * @param path
     *            - content path
     * @param name - loaded file name
     * @param summary - file description
     * @param loadDate
     *            - date when content was loaded
     * @param owner
     *            - content owner
     */
    public Content(long id, String path, String name, String summary,
	    Date loadDate, User owner) {
	this.id = id;
	this.path = path;
	this.name = name;
	this.summary = summary;
	this.loadDate = loadDate;
	this.owner = owner;
    }

    /**
     * Get unique content id.
     * 
     * @return the id
     */
    @Id
    @Column(name = "WE_ID")
    @GeneratedValue(strategy = GenerationType.SEQUENCE)
    public long getId() {
	return id;
    }

    /**
     * Set unique content id.
     * 
     * @param id
     *            - unique content id.
     */
    public void setId(long id) {
	this.id = id;
    }

    /**
     * Get content path.
     * 
     * @return the path
     */
    @Column(name = "WE_PATH", nullable = false, unique = true)
    public String getPath() {
	return path;
    }

    /**
     * Set content parh.
     * 
     * @param path
     *            where storage content
     */
    public void setPath(String path) {
	this.path = path;
    }

    /**
     * Get content load date.
     * 
     * @return the loadDate
     */
    @Temporal(TemporalType.TIMESTAMP)
    @Column(name = "WE_LOAD_DATE", nullable = false)
    public Date getLoadDate() {
	return loadDate;
    }

    /**
     * Set content load date.
     * 
     * @param loadDate
     *            - date when content was loaded
     */
    public void setLoadDate(Date loadDate) {
	this.loadDate = loadDate;
    }

    /**
     * Get content owner
     * 
     * @return the owner
     */
    @ManyToOne(cascade = CascadeType.ALL)
    @JoinColumn(name = "WE_OWNER_ID")
    public User getOwner() {
	return owner;
    }

    /**
     * Set content owner
     * 
     * @param owner
     *            - content owner
     */
    public void setOwner(User owner) {
	this.owner = owner;
    }

    /**
     * Get file name.
     * 
     * @return the name
     */
    @Column(name = "WE_NAME", updatable = true)
    public String getName() {
        return name;
    }

    /**
     * Set file name.
     * 
     * @param name - loaded file name
     */
    public void setName(String name) {
        this.name = name;
    }

    /**
     * Get file summary.
     * 
     * @return the summary
     */
    @Column(name = "WE_SUMMARY", updatable = true)
    public String getSummary() {
        return summary;
    }

    /**
     * Set file summary
     * 
     * @param summary - loaded file description
     */
    public void setSummary(String summary) {
        this.summary = summary;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public int hashCode() {
	final int prime = 31;
	int result = 1;
	result = prime * result + (int) (id ^ (id >>> 32));
	return result;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public boolean equals(Object obj) {
	if (this == obj)
	    return true;
	if (obj == null)
	    return false;
	if (getClass() != obj.getClass())
	    return false;
	Content other = (Content) obj;
	if (id != other.id)
	    return false;
	return true;
    }
    
}
